
* Set Working Directory
* cd ""

********** WRONSKI ET AL. (2018) REPRODUCTION AND REANALYSIS **********

use CCES_YouGov.dta, clear

gen Primary_TrumpvCruz = 1-Primary_CruzvTrump /// Flip Trump and Cruz so Trump=1, Cruz=0. 

***** MAIN TEXT REPRODUCTIONS *****

* Democrats - CCES - Figure 2 and Table 2
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5, robust
margins, at(RWA_combined=(0(0.25)1)) post
marginsplot, ytitle(Pr(Clinton over Sanders), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("    CCES", size(vlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)

* Democrats - YouGov - Figure 2 and Table 2
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined NEED_close SDO Racial  if caseid !=. , robust
margins, at(RWA_combined=(0(0.25)1)) post
marginsplot, ytitle(Pr(Clinton over Sanders), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("   YouGov", size(vlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)

* Republicans - CCES - Figure 2 and Table 2
regress Primary_TrumpvCruz RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5, robust
margins, at(RWA_combined=(0(0.25)1)) post
marginsplot, ytitle(Pr(Trump over Cruz), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("    CCES", size(vlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)

* Republicans - YouGov - Figure 2 and Table 2
regress Primary_TrumpvCruz  RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined NEED_close SDO Racial  if caseid !=. , robust
margins, at(RWA_combined=(0(0.25)1)) post
marginsplot, ytitle(Pr(Trump over Cruz), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("   YouGov", size(vlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)


***** MAIN TEXT RANDOM EFFECTS ESTIMATES *****

* Democrats - CCES
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5, robust
* Democrats - YouGov - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. , robust
* Republicans - CCES 
regress Primary_TrumpvCruz RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5, robust
* Republicans - YouGov - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
regress Primary_TrumpvCruz  RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. , robust


***** APPENDIX D - Analyses without Party Identity Strength and Ideology Covariates *****

* Democrats - CCES - Table D1
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5 & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5 & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5 & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined  ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5 & Dem_PID_combined != . & Ideology_combined != ., robust

* Democrats - YouGov - Table D1 - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Dem_PID_combined != . & Ideology_combined != ., robust
regress Primary_ClintonvsSanderscombined RWA_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Dem_PID_combined != . & Ideology_combined != ., robust

* Republicans - CCES - Table D2
regress Primary_TrumpvCruz RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5 & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz RWA_combined Rep_PID_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5 & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz RWA_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5 & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz RWA_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5 & Rep_PID_combined != . & Ideology_combined != ., robust

* Republicans - YouGov - Table D2 - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
regress Primary_TrumpvCruz  RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz  RWA_combined Rep_PID_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz  RWA_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Rep_PID_combined != . & Ideology_combined != ., robust
regress Primary_TrumpvCruz  RWA_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. & Rep_PID_combined != . & Ideology_combined != ., robust


***** APPENDIX F - Results with Logistic Regression Models *****

* Democrats - CCES - Table F1
logit Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID < 0.5, robust
margins, dydx(RWA_combined)
* Democrats - YouGov - Table F1 - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
logit Primary_ClintonvsSanderscombined RWA_combined Dem_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. , robust
margins, dydx(RWA_combined)
* Republicans - CCES - Table F2
logit Primary_TrumpvCruz RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if V101 !=.  & PID > 0.5, robust
margins, dydx(RWA_combined)
* Republicans - YouGov - Table F2 - Note: Need for closure, social dominance, and racial resentment dropped from YouGov models for random effects model.
logit Primary_TrumpvCruz  RWA_combined Rep_PID_combined Ideology_combined ReligiousAttend_combined Gender_combined White_combined  Education_Combined Income Union_Combined Married_Combined Age_Combined South_Combined if caseid !=. , robust
margins, dydx(RWA_combined)


********** 2016 AMERICAN NATIONAL ELECTION STUDY ANALYSIS **********

use ANES2016.dta, clear

***** CODE VARIABLES *****

* Sampling Design
gen weight = V160102
gen strata = V160201
gen psu = V160202
svyset [pweight = weight],  strata(strata) psu(psu)

* Demographics
gen male = .
replace male = 1 if V161342 == 1
replace male = 0 if V161342 != 1
label variable male "Male"

gen race = .
replace race = 1 if V161310x == 1
replace race = 2 if V161310x == 2
replace race = 3 if V161310x == 5
replace race = 4 if V161310x == 3
replace race = 5 if V161310x == 4
replace race = 6 if V161310x == 6 | V161310x == -2
label define racelabel 1 "White" 2 "Black" 3 "Hispanic" 4 "Asian/PI" 5 "Native" 6 "Multi"
label values race racelabel

gen white = .
replace white = 1 if race == 1
replace white = 0 if race != 1 & race != .
label variable white "White"

gen black = .
replace black = 1 if race == 2
replace black = 0 if race != 2 & race != .
label variable black "Black"

gen hispanic = .
replace hispanic = 1 if race == 3
replace hispanic = 0 if race != 3 & race != .
label variable hispanic "Hispanic"

gen education = .
replace V161270 = 9 if V161270 == 90
replace education = (V161270-1)/15 if V161270 > 0 & V161270 < 90
label variable education "Education"

gen parent = .
replace parent = 1 if V161324 > 0
replace parent = 0 if V161324 == 0 | V161324 == -9
label variable parent "Parent"

gen married = .
replace married = 1 if V161268 == 1 | V161268 == 2
replace married = 0 if V161268 > 2 | V161268 == -9
label variable married "Married"

gen age = .
replace age = (V161267-18)/72 if V161267 > 17
label variable age "Age"

gen south = .
replace south = 1 if V163003 == 3 
replace south = 0 if V163003 != 3
label variable south "South"

gen union = .
replace union = 1 if V161302 == 1
replace union = 0 if V161302 != 1
label variable union "Union"

gen income_noimpute = .
replace income_noimpute = (V161361x-1)/27 if V161361x > 0
impute income_noimpute age union male education black hispanic married, gen(income)
label variable income "Income"

gen churchattendance = .
replace churchattendance = 1-(V161245-1)/4 if V161245 > 0
replace churchattendance = 0 if V161245 == 5 | V161244 == 2
label variable churchattendance "Church Attendance"

* Party and Ideology
gen pid7 = .
replace pid7 = (V161158x-1)/6 if V161158x > 0
gen pid01 = pid7

gen pidstrdem = .
replace pidstrdem = 1 if V161158x == 1
replace pidstrdem = .5 if V161158x == 2
replace pidstrdem = 0 if V161158x == 3
label variable pidstrdem "PID Strength"

gen pidstrrep = .
replace pidstrrep = 1 if V161158x == 7
replace pidstrrep = .5 if V161158x == 6
replace pidstrrep = 0 if V161158x == 5
label variable pidstrdem "PID Strength"

gen democrat = 0
replace democrat = 1 if pid7 < .5 /// includes leaners

gen republican = 0
replace republican = 1 if pid7 > .5 /// includes leaners

gen ideo7 = .
replace V161126 = 4 if V161126 == 99
replace ideo7 = (V161126-1)/6 if V161126 > 0 & V161126 < 10
gen ideo01 = ideo7
label variable ideo01 "Ideology"

* Authoritarianism Index
gen auth1 = .
replace auth1 = 1 if V162239== 2
replace auth1 = .5 if V162239 == 3
replace auth1 = 0 if V162239 == 1
gen auth2 = .
replace auth2 = 1 if V162240 == 2
replace auth2 = .5 if V162240 == 3
replace auth2 = 0 if V162240 == 1
gen auth3 = .
replace auth3 = 1 if V162241 == 1
replace auth3 = .5 if V162241 == 3
replace auth3 = 0 if V162241 == 2
gen auth4 = .
replace auth4 = 1 if V162242 == 2
replace auth4 = .5 if V162242 == 3
replace auth4 = 0 if V162242 == 1

alpha auth1 auth2 auth3 auth4, generate(auth_scale)
label variable auth_scale "Authoritarianism"

* Primary Vote
gen demprimary2016 = .
replace demprimary2016 = 1 if V161021a == 1
replace demprimary2016 = 0 if V161021a == 2 
label variable demprimary2016 "Vote for Clinton vs. Sanders in 2016 Dem Primary"

gen repprimary2016 = V161021a if V161021a >= 4 & V161021a <= 7
replace repprimary2016 = repprimary2016-3
label define repprimary2016l 1 "Trump" 2 "Cruz" 3 "Kasich" 4 "Rubio"
label values repprimary2016 repprimary2016l

gen trumpvoter = .
replace trumpvoter = 1 if repprimary2016 == 1
replace trumpvoter = 0 if repprimary2016 == 2 | repprimary2016 == 3 | repprimary2016 == 4

* Supplemental Controls for MacWilliams (2016) Model Replication
gen terror_worry = .
replace terror_worry = 1-(V162160-1)/4 if V162160 > 0 

gen evangelical = 0
replace evangelical = 1 if V161265x == 2


***** Summary Statistics - Table 3 *****

* Remove respondents who will be deleted via listwise deletion before doing summary stats
drop if republican == 1 & (repprimary2016 == . | male == . | auth_scale == . | pidstrrep  == . | ideo01  == . | churchattendance  == . | male  == . | white  == . | education  == . | income  == . | union  == . | married  == . | age  == . | south == .)
drop if democrat == 1 & (demprimary2016 == . | male == . | auth_scale == . | pidstrdem  == . | ideo01  == . | churchattendance  == . | male  == . | white  == . | education  == . | income  == . | union  == . | married  == . | age  == . | south == .)

svy, subpop(democrat): mean auth_scale
svy, subpop(republican): mean auth_scale
svy, subpop(democrat): tab demprimary2016
svy, subpop(republican): tab repprimary2016


***** MAIN RESULTS *****

* Democrats - Table 4 and Figure 3
svy, subpop(democrat): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.union i.married age i.south
margins, at(auth_scale=(0(0.25)1)) post
marginsplot, ytitle(Pr(Clinton over Sanders), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) title("     ANES", size(vlarge)) recastci(rspike) recast(connected)

* Republicans - Table 5 and Figure 4
svy, subpop(republican): mprobit repprimary2016 auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south
margins, dydx(auth_scale)
margins, at(auth_scale=(0(0.25)1) married == 1 male == 0 white == 1 south == 0 union == 0) atmeans post 
marginsplot, ytitle(Predicted Probability, size(medlarge)) xtitle(Authoritarianism, size(medlarge)) legend(rows(1) size(medium) order(5 "Trump" 6 "Cruz" 7 "Kasich" 8 "Rubio")) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) title("      ANES", size(vlarge)) recastci(rspike) recast(connected)

* Republicans - Binary Linear Probability Estimate for Random Effects
svy, subpop(republican): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south


***** APPENDIX C - 2016 Republican Primary Analysis with MacWilliams (2016) Model ***** 
svy, subpop(republican): logit trumpvoter auth_scale ideo01 churchattendance i.male i.white education income age i.evangelical terror_worry c.auth_scale#c.terror_worry
margins, dydx(auth_scale)
margins, at(auth_scale=(0(0.25)1) male == 0 white == 1 evangelical == 0) atmeans post
marginsplot, ytitle(Pr(Trump over Others), size(medlarge)) xtitle(Authoritarianism, size(medlarge))  yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) title("      ANES", size(vlarge)) recastci(rspike) recast(connected)


***** APPENDIX D - Analyses without Party Identity Strength and Ideology Covariates *****

* Democrats - Table D1
svy, subpop(democrat): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(democrat): regress demprimary2016 auth_scale pidstrdem churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(democrat): regress demprimary2016 auth_scale ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(democrat): regress demprimary2016 auth_scale churchattendance i.male i.white education income i.union i.married age i.south

* Republicans - Table D2
svy, subpop(republican): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(republican): regress trumpvoter auth_scale pidstrrep churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(republican): regress trumpvoter auth_scale ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(republican): regress trumpvoter auth_scale churchattendance i.male i.white education income i.union i.married age i.south

***** APPENDIX F - Results with Logistic Regression Models *****
svy, subpop(democrat): logit demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.union i.married age i.south
margins, dydx(auth_scale)
svy, subpop(republican): logit trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south
margins, dydx(auth_scale)

***** APPENDIX G - 2016 ANES Analyses by Survey Mode ***** 
svy, subpop(democrat if V160501==1): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(democrat if V160501==2): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(republican if V160501==1): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south
svy, subpop(republican if V160501==2): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.union i.married age i.south

********** 2016 PRRI SURVEY ANALYSIS **********
use PRRI2016.dta, clear
svyset[pweight=weight]

* Demographics
gen male = .
replace male = 1 if GENDER == 1
replace male = 0 if GENDER != 1
label variable male "Male"

gen age = .
replace age = (AGE-18)/81 if AGE < 100
label variable age "Age"

gen education = .
replace education = (EDUC4-1)/3 if EDUC4 < 9
label variable education "Education"

gen white = 0
replace white = 1 if RACETHNICITY == 1 
label variable white "White"

gen black = 0
replace black = 1 if RACETHNICITY == 2 
label variable black "Black"

gen hispanic = 0
replace hispanic = 1 if RACETHNICITY == 4
label variable hispanic "Hispanic"

gen unemployed = .
replace unemployed = 1 if EMPLOY == 6 | EMPLOY == 7
replace unemployed = 0 if EMPLOY != 6 & EMPLOY != 7
label variable unemployed "Unemployed"

gen married = .
replace married = 1 if MARITAL == 1
replace married = 0 if MARITAL != 1
label variable married "Married"

gen south = .
replace south = 1 if REGION4 == 3
replace south = 0 if REGION4 != 3
label variable south "South"

gen income_noimpute = .
replace income_noimpute = (INCOME-1)/17 if INCOME < 19
impute income_noimpute age male education black hispanic married unemployed, gen(income)
label variable income "Income"

gen churchattendance = 1-(ATTEND-1)/5 if ATTEND != 9
label variable churchattendance "Church Attendance"

* Supplemental Controls for MacWilliams (2016) Model Replication
gen evangelical = 0
replace evangelical = 1 if BORN == 1

gen terror_worry = .
replace terror_worry = 1-(Q34A-1)/3
replace terror_worry = .5 if Q34A == 9

* Authoritarianism Index
gen auth1 = .
replace auth1 = 1 if Q32A == 2
replace auth1 = 0 if Q32A == 1
gen auth2 = .
replace auth2 = 1 if Q32B == 2
replace auth2 = 0 if Q32B == 1
gen auth3 = .
replace auth3 = 1 if Q32C == 2
replace auth3 = 0 if Q32C == 1
gen auth4 = .
replace auth4 = 1 if Q32D == 2
replace auth4 = 0 if Q32D == 1

alpha auth1 auth2 auth3 auth4, generate(auth_scale)
label variable auth_scale "Authoritarianism"

* Political Identity
gen pid01 = .
replace pid01 = 1 if PARTY == 1
replace pid01 = (3/4) if PARTYLN == 1
replace pid01 = (2/4) if PARTYLN == 3 | PARTYLN == 9
replace pid01 = (1/4) if PARTYLN == 2
replace pid01 = 0 if PARTY == 2

gen democrat = 0
replace democrat = 1 if pid01 < .5

gen republican = 0
replace republican = 1 if pid01 > .5

gen pidstrdem = .
replace pidstrdem = 1 if PARTY == 2
replace pidstrdem = 0 if PARTYLN == 2
label variable pidstrdem "PID Strength"

gen pidstrrep = .
replace pidstrrep = 1 if PARTY == 1
replace pidstrrep = 0 if PARTYLN == 1
label variable pidstrrep "PID Strength"

gen ideo01 = .
replace ideo01 = 1-(IDEO-1)/4 if IDEO < 8
replace ideo01 = .5 if IDEO == 9
label variable ideo01 "Ideology"

* Voter Screens 
gen potentialprimary = 0
replace potentialprimary = 1 if Q2 != 5 & Q3 != 2
gen likelyprimary = 0
replace likelyprimary = 1 if Q2 == 1 
replace likelyprimary = 0 if Q3 == 2

* Primary Candidate Preferences
gen demprimary2016 = .
replace demprimary2016 = 1 if Q6 == 1
replace demprimary2016 = 0 if Q6 == 2 
label variable demprimary2016 "Pref in 2016 Dem Primary"

gen repprimary2016 = .
replace repprimary2016 = Q8 if Q8 < 4
recode repprimary2016 1=2 2=1 3=3
label define repprimary2016l 2 "Ted Cruz" 1 "Donald Trump" 3 "John Kasich"
label values repprimary2016 repprimary2016l
label variable repprimary2016 "Pref in 2016 GOP Primary"

gen trumpvoter = .
replace trumpvoter = 1 if repprimary2016 == 1
replace trumpvoter = 0 if repprimary2016 == 2 | repprimary2016 == 3


***** Summary Statistics - Table 3 *****
drop if republican == 1 & (repprimary2016 == . | male == . | auth_scale == . | pidstrrep  == . | ideo01  == . | churchattendance  == . | male  == . | white  == . | education  == . | income  == . | married  == . | age  == . | south == .)
drop if democrat == 1 & (demprimary2016 == . | male == . | auth_scale == . | pidstrdem  == . | ideo01  == . | churchattendance  == . | male  == . | white  == . | education  == . | income  == . |  married  == . | age  == . | south == .)

svy, subpop(democrat if potentialprimary == 1): mean auth_scale
svy, subpop(republican if potentialprimary == 1): mean auth_scale
svy, subpop(democrat if potentialprimary == 1): tab demprimary2016
svy, subpop(republican if potentialprimary == 1): tab repprimary2016


***** MAIN RESULTS *****

* Democrats - Table 4 and Figure 3
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south
margins, at(auth_scale=(0(0.25)1)) post
marginsplot, ytitle(Pr(Clinton over Sanders), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) title("     PRRI", size(vlarge)) recastci(rspike) recast(connected)

* Republicans - Table 5 and Figure 4
svy, subpop(republican if potentialprimary == 1): mprobit repprimary2016 auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south
margins, dydx(auth_scale)
margins, at(auth_scale=(0(0.25)1) married == 1 male == 1 white == 1 south == 0) atmeans post 
marginsplot, ytitle(Pr(Candidate Support), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("     2016 PRRI", size(vlarge)) legend(rows(1) size(medium) order(4 "Trump" 5 "Cruz" 6 "Kasich" )) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)

* Republicans - Binary Linear Probability Estimate for Random Effects
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south


***** APPENDIX C - 2016 Republican Primary Analysis with MacWilliams (2016) Model *****
svy, subpop(republican if potentialprimary == 1): logit trumpvoter auth_scale ideo01 churchattendance i.male i.white education income age i.evangelical terror_worry c.auth_scale##c.terror_worry
margins, dydx(auth_scale)
margins, at(auth_scale=(0(0.25)1) male == 1 white == 1 evangelical==1) atmeans post 
marginsplot, ytitle(Pr(Trump over Others), size(medlarge)) xtitle(Authoritarianism, size(medlarge)) title("     PRRI", size(vlarge)) yline(0(.25)1, lcolor(gs15)) xlabel(0(.25)1) ylabel(0(.25)1) recastci(rspike) recast(connected)


***** APPENDIX D - Analyses without Party Identity Strength and Ideology Covariates *****

* Democrats - Table D1
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale pidstrdem churchattendance i.male i.white education income i.married age i.south
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale churchattendance i.male i.white education income i.married age i.south

* Republicans - Table D2
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale pidstrrep churchattendance i.male i.white education income i.married age i.south
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale churchattendance i.male i.white education income i.married age i.south


*********** APPENDIX E - PRRI Results with Different Voter Subsets *************

* Democrats - Table E1
svy, subpop(democrat if potentialprimary == 1): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(democrat if likelyprimary == 1): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south 
svy, subpop(democrat): regress demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south

* Republicans - Table E2
svy, subpop(republican if potentialprimary == 1): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south 
svy, subpop(republican if likelyprimary == 1): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south
svy, subpop(republican): regress trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south


*********** APPENDIX F - Results with Logistic Regression Models *************

* Democrats - Table F1
svy, subpop(democrat if potentialprimary == 1): logit demprimary2016 auth_scale pidstrdem ideo01 churchattendance i.male i.white education income i.married age i.south
margins, dydx(auth_scale)

* Republicans - Table F2
svy, subpop(republican if potentialprimary == 1): logit trumpvoter auth_scale pidstrrep ideo01 churchattendance i.male i.white education income i.married age i.south
margins, dydx(auth_scale)





